//
//  HXRecommendSortTableViewCell.m
//  百思不得姐
//
//  Created by ifly on 16/3/22.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXRecommendSortTableViewCell.h"
#import "XMGRecommendCategory.h"

@interface HXRecommendSortTableViewCell()
@property (weak, nonatomic) IBOutlet UIView *selectedIndicator;
@end

@implementation HXRecommendSortTableViewCell

- (void)awakeFromNib {
    self.backgroundColor = XMGRGBColor(244, 244, 244);
    self.selectedIndicator.backgroundColor = XMGRGBColor(219, 21, 26);
    // 当cell的selection为None时, cell被选中时, 内部的子控件就不会进入高亮状态 但是还会调用selected方法
    //    self.textLabel.textColor = XMGRGBColor(78, 78, 78);
    /**当选中label他内部所有空间进入高亮状态*/
    /**但是如果xib里面设置cell selection 为none  cell不会进入highlighted状态*/
    //    self.textLabel.highlightedTextColor = XMGRGBColor(219, 21, 26);
    //    UIView *bg = [[UIView alloc] init];
    //    bg.backgroundColor = [UIColor clearColor];
    /**选中时的背景view*/
    //    self.selectedBackgroundView = bg;
}

- (void)setCategory:(XMGRecommendCategory *)category{
    _category = category;
    self.textLabel.text = _category.name;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 重新调整内部textLabel的frame
    self.textLabel.y = 2;
    self.textLabel.height = self.contentView.height - 2 * self.textLabel.y;
}

//当点击cell的时候cell进入选中 调用cell的Selected
//当取消选中的时候也调用 传no
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
    
    self.selectedIndicator.hidden = !selected;
    self.textLabel.textColor = selected ? self.selectedIndicator.backgroundColor : XMGRGBColor(78, 78, 78);
}

@end
